package com.ruoyi.common.utils;

import com.alibaba.fastjson.JSONObject;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import java.util.Date;

public class SignUtils {


    /**
     * BASE64解密
     *
     * @throws Exception
     */
    public static byte[] decryptBASE64(String key) throws Exception {
        return (new BASE64Decoder()).decodeBuffer(key);
    }

    /**
     * BASE64加密
     */
    public static String encryptBASE64(byte[] key) throws Exception {
        return (new BASE64Encoder()).encodeBuffer(key);
    }

    public static void main(String[] args) throws Exception {
        String appId = "LinkCredit_PDL";
        String apiKey = "Y0MTQ2NjA2MjcwMg";
        long time = new Date().getTime();
        long timestamp = 1638878007500l;//13位的当前时间戳
        String param = "appId=" + appId + "&apiKey=" + apiKey + "&timestamp=" + time;
        String sign = encryptBASE64(param.getBytes());
        System.err.println(sign);


       System.out.println(new String(decryptBASE64(sign)));


    }

    public static JSONObject argsToJson (String single){
        String[] p = single.split("&");
        JSONObject jsonObject = new JSONObject();
        for (int s = 0; s < p.length; s++) {
            String cc = p[s];
            String[] split = cc.split("=");
            jsonObject.put(split[0],split[1]);
        }
        return jsonObject;
    }



}
